package com.hn.common.utils.ding;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiAttendanceGetattcolumnsRequest;
import com.dingtalk.api.request.OapiAttendanceGetcolumnvalRequest;
import com.dingtalk.api.response.OapiAttendanceGetattcolumnsResponse;
import com.dingtalk.api.response.OapiAttendanceGetcolumnvalResponse;
import com.taobao.api.ApiException;
import com.taobao.api.internal.util.StringUtils;

/**
 *  钉钉考勤
 * @author admin
 */
public class DingAttendanceUtil {
    public static void main(String[] args) throws ApiException {
//        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/isopensmartreport");
//        OapiAttendanceIsopensmartreportRequest req = new OapiAttendanceIsopensmartreportRequest();
//        OapiAttendanceIsopensmartreportResponse rsp = client.execute(req, AccessTokenUtil.getToken());
//        System.out.println(rsp.getBody());

/*        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/listRecord");
        OapiAttendanceListRecordRequest request = new OapiAttendanceListRecordRequest();
        request.setCheckDateFrom("2018-05-01 00:00:00");
        request.setCheckDateTo("2018-05-05 00:00:00");
        request.setUserIds(Arrays.asList("123"));
        OapiAttendanceListRecordResponse execute = client.execute(request,AccessTokenUtil.getToken());*/

      /*  DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
        OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
        req.setUserid("050210155830215836");
        req.setColumnIdList("1,2,3");
        req.setFromDate(StringUtils.parseDateTime("2020-06-01 12:12:12"));
        req.setToDate(StringUtils.parseDateTime("2020-06-09 12:12:12"));
        OapiAttendanceGetcolumnvalResponse rsp = client.execute(req, AccessTokenUtil.getToken());
        System.out.println(rsp.getBody());*/
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getattcolumns");
        OapiAttendanceGetattcolumnsRequest req = new OapiAttendanceGetattcolumnsRequest();
        OapiAttendanceGetattcolumnsResponse rsp = client.execute(req, AccessTokenUtil.getToken());
        System.out.println(rsp.getBody());

    }

    public static void listAttendances() throws ApiException{
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
        OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
        req.setUserid("050210155830215836");
        req.setColumnIdList("1");
        req.setFromDate(StringUtils.parseDateTime("2020-06-01 08:12:12"));
        req.setToDate(StringUtils.parseDateTime("2020-06-09 08:12:12"));
        OapiAttendanceGetcolumnvalResponse rsp = client.execute(req, AccessTokenUtil.getToken());
        System.out.println(rsp.getBody());
    }
}
